import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
import { Input as AntdInput } from 'antd';
import React from 'react';
import { useFieldContext } from '../../contexts/FieldContext';
import { useFormContext } from '../../contexts/FormContext';
import createField from '../../createField';
import { getExtraProps, getRulesFromProps } from './utils';
var _excluded = ['maxLength', 'valueType'];
var TextArea = function TextArea(_ref) {
  var _ref$maxLength = _ref.maxLength,
    maxLength = _ref$maxLength === void 0 ? 250 : _ref$maxLength,
    valueType = _ref.valueType,
    props = _objectWithoutProperties(_ref, _excluded);
  var form = useFormContext();
  var _useFieldContext = useFieldContext(),
    label = _useFieldContext.label;
  var extraProps = getExtraProps(
    _objectSpread(
      {
        valueType: valueType,
      },
      props,
    ),
    form,
  );
  return /*#__PURE__*/ React.createElement(
    AntdInput.TextArea,
    _objectSpread(
      _objectSpread(
        {
          placeholder: '\u8BF7\u8F93\u5165'.concat(label),
          maxLength: maxLength,
        },
        extraProps,
      ),
      props,
    ),
  );
};
export default createField(TextArea, {
  defaultDetailType: 'text',
  getFormItemPropsFromProps: function getFormItemPropsFromProps(props, form) {
    return {
      rules: getRulesFromProps(props, form),
      style: props.formItemStyle
        ? _objectSpread(
            _objectSpread({}, props.formItemStyle),
            {},
            {
              visibility: !props.hidden ? 'inherit' : 'hidden',
            },
          )
        : props.hidden
        ? {
            display: 'none',
          }
        : undefined,
    };
  },
});
